﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;
using System.Windows;
using ThreeByte.Media;
using ThreeByte.Controls;

namespace ThreeByte.ActiveDeck.AddIn.Content.Controls
{
    public class DesignerMoveThumb : Thumb
    {
        public DesignerMoveThumb() {
            DragDelta += new DragDeltaEventHandler(DesignerMoveThumb_DragDelta);
        }

        void DesignerMoveThumb_DragDelta(object sender, DragDeltaEventArgs e) {

            DesignerControl designerItem = this.DataContext as DesignerControl;

            //TODO: Clamp the item here
            if(designerItem != null) {
                designerItem.CurrentPixelSpace.X = (int)PixelSpace.ClampLeft(designerItem.CurrentPixelSpace, Bounds, designerItem.CurrentPixelSpace.X + (int)(e.HorizontalChange));
                designerItem.CurrentPixelSpace.Y = (int)PixelSpace.ClampTop(designerItem.CurrentPixelSpace, Bounds, designerItem.CurrentPixelSpace.Y + (int)(e.VerticalChange));
            }
        }

        public static readonly DependencyProperty BoundaryProperty = DependencyProperty.Register("Bounds",
            typeof(Boundary), typeof(DesignerMoveThumb), new FrameworkPropertyMetadata(Boundary.Universe));

        public Boundary Bounds {
            get {
                return (Boundary)GetValue(BoundaryProperty);
            }
            set {
                SetValue(BoundaryProperty, value);
            }
        }
    }
}
